<?php
/**
 * @version     1.0.1
 * @package     com_ganeshavereadores
 * @copyright  	
 * @license     
 * @author      Jorge Eduardo
 */
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive');

$params		= &$this->item->params;
$n			= count($this->items);
$listOrder	= $this->escape($this->state->get('list.ordering'));
$listDirn	= $this->escape($this->state->get('list.direction'));

$filter_vereador = $this->state->get('filter.vereador');
$filter_categoria = $this->state->get('filter.categoria');
$filter_ano = $this->state->get('filter.ano');


?>

<div class="container proposicoes">
	<h3>Proposições</h3>
	
	<div class="content">
	
	<form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm" class="form-inline">
		<?php if ($this->params->get('show_headings') || $this->params->get('filter_field') != 'hide' || $this->params->get('show_pagination_limit')) :?>
		<fieldset >
			<?php if ($this->params->get('filter_field') != 'hide') :?>
				
						<?php 
							$db =& JFactory::getDBO();
							$sql = 'SELECT id, nome FROM #__ganeshavereadores_vereadores order by nome asc';
							$db->setQuery($sql);
							
							$vereadorlist[] = JHTML::_('select.option',  '0' , JText::_( ' Selecione um Vereador ' ), 'id', 'nome' );
							$vereadorlist = array_merge( $vereadorlist, $db->loadObjectList() );
						?>					
						<select name="filter-vereador" id="filter-vereador" onchange="changeHandlerVereador()"> >
							<?php foreach ($vereadorlist as $vereador) :?>
								<option value="<?php echo $vereador->id ?>"  <?php if($vereador->id == $filter_vereador) echo 'selected="true"'?>><?php echo $vereador->nome ?></option>						
							<?php endforeach;?>						
						</select>																									
				
					<?php 
						$db =& JFactory::getDBO();
						$sql = 'SELECT distinct a.id, a.nome FROM #__ganeshavereadores_categoria a left join #__ganeshavereadores_proposicoes b on b.categoria=a.id where '; 
						if($filter_vereador)
							$sql .= ' b.vereador='.$filter_vereador;
						else
							$sql .= ' b.vereador=0';
							
						$sql .=' order by a.nome';	
						$db->setQuery($sql);
						$categorialist[] = JHTML::_('select.option',  '0', JText::_( ' Selecione uma Atividade ' ), 'id', 'nome' );
						$categorialist = array_merge( $categorialist, $db->loadObjectList() );
					?>						
					<select name="filter-categoria" id="filter-categoria" onchange="changeHandlerCategoria();">
						<?php foreach ($categorialist as $categoria) :?>
							<option value="<?php echo $categoria->id ?>"  <?php if($categoria->id == $filter_categoria) echo 'selected="true"'?>><?php echo $categoria->nome ?></option>						
						<?php endforeach;?>
					</select>
					
						<?php 
							$db =& JFactory::getDBO();
							$sql = 'SELECT distinct ano FROM  #__ganeshavereadores_proposicoes where '; 
							if($filter_categoria)
								$sql .= ' categoria='.$filter_categoria .' AND ';
							else
								$sql .= ' categoria=0 AND ';	

							if($filter_vereador)
								$sql .= ' vereador='.$filter_vereador;
							else
								$sql .= ' vereador=0';	
							
							$sql .=' order by ano';
							
							$db->setQuery($sql);
							$anolist[] = JHTML::_('select.option',  '0', JText::_( ' Selecione um Ano ' ), 'ano', 'ano' );
							$anolist = array_merge( $anolist, $db->loadObjectList() );
						?>						
						<select name="filter-ano" id="filter-ano" onchange="document.adminForm.submit();">
						<?php foreach ($anolist as $ano) :?>
							<option value="<?php echo $ano->ano ?>"  <?php if($ano->ano == $filter_ano) echo 'selected="true"'?>><?php echo $ano->ano ?></option>						
						<?php endforeach;?>
					</select>
											
		<?php endif; ?>
		
		<input type="hidden" name="filter_order" value="" />
		<input type="hidden" name="filter_order_Dir" value="" />
		<input type="hidden" id="limitstart" name="limitstart" value="" />
		<input type="hidden" name="task" value="" />
		
	</fieldset>
	<?php endif; ?>
	
	
	
	<ul>
<?php foreach ($this->items as $item) : 
		echo '<li>';
 		echo '<a title="'.$this->escape($item->titulo).'" href="'. JRoute::_('index.php?option=com_ganeshavereadores&view=proposicao&id=' . (int)$item->id) .'">' . 
 		$this->escape($item->catalias) . ' ' . $this->escape($item->numero)  .' </a>' . $this->escape($item->titulo) . '</li>';
	  endforeach; ?>
  </ul>
	  </div>
	  
	  
	</div>
	  

<?php if (!empty($this->items)) : ?>
	<?php if (($this->params->def('show_pagination', 2) == 1  || ($this->params->get('show_pagination') == 2)) && ($this->pagination->pagesTotal > 1)) : ?>
	<div class="pagination">
		
		<div class="btnback">
			<a href="javascript:window.history.back()" title="Voltar à página anterior" ><img src="<?php echo JUri::base() ?>templates/cmmacae/img/btnBack.jpg" /></a>
		</div>
		
		<div class="pag">
		
		<?php echo $this->pagination->getPagesLinks(); ?>
		</div>
	</div>
	<?php endif; ?>

<?php  endif; ?>


	
	
</form>

	